package org.op.editor;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class ReplaceDialogViewImpl implements ReplaceDialogView {

	private JOptionPane optionPane;
	
	public String[] openAndGet(JFrame frame, String title, String searchLabelMsg, String replaceLabelMsg) {
		String[] sar = new String[2];
		
		JLabel searchLabel = new JLabel(searchLabelMsg);
		JTextField searchField = new JTextField();
		JLabel replaceLabel = new JLabel(replaceLabelMsg);
		JTextField replaceField = new JTextField();
		
		Object[] body = {searchLabel, searchField, replaceLabel, replaceField};
		
        //Create the JOptionPane.
        optionPane = new JOptionPane(body,
                                    JOptionPane.QUESTION_MESSAGE,
                                    JOptionPane.OK_CANCEL_OPTION);
        
        JDialog dialog = optionPane.createDialog(frame, title);
        dialog.setVisible(true);
		
        Object selectedValue = optionPane.getValue();
        if (selectedValue.equals(JOptionPane.CANCEL_OPTION)) {
        	// do nothing
        } else {
        	sar[0] = searchField.getText();
        	sar[1] = replaceField.getText();
        }
		
		return sar;
	}

}
